use strict;
use warnings;
use FindBin qw[$Bin];
use Test::More qw[no_plan];
use Test::Exception;

use_ok 'Grantsfire';

my %FEEDS = (
  empty     =>  q[],
  malformed =>  q[Hi there.],
  missing   =>  q[http://grantsfire.org:1337/bunk.xml],
  passing   =>  q[http://www.mott.org/about/programs/grantrssfeed.aspx],
  warnings  => qq[file://$Bin/warnings.html],
  critical  => qq[file://$Bin/critical.html],
  mixture   => qq[file://$Bin/mixture.html],
);

my $VALIDATOR = 'Grantsfire::Schema::Feed::Validator';
my $EXCEPTION = "$VALIDATOR\::Exceptions";
my $CLASS     = 'Grantsfire::Schema::Feed';
my $METHOD    = 'ValidateFeed';
sub _C ($;) { $CLASS->$METHOD(shift) }
sub _E ($;) { join '::', $EXCEPTION, shift }

can_ok $CLASS, $METHOD;

throws_ok { _C $FEEDS{empty}     } _E 'Empty';
throws_ok { _C $FEEDS{malformed} } _E 'Malformed';
throws_ok { _C $FEEDS{missing}   } _E 'NotFound';

PASSING: {
  my $V;
  lives_ok { $V = _C $FEEDS{passing} } 'Passing feed should build and return';
  isa_ok $V, $VALIDATOR;
  
  cmp_ok @{$V->hgrants}, '>', 0, 'We found some solid hGrants';
}

WARNINGS: {
  my $V;
  lives_ok { $V = _C $FEEDS{warnings} } 'Warnings feed should build and return';
  isa_ok $V, $VALIDATOR;

  cmp_ok @{$V->hgrants}, '>', 0, 'We found some solid hGrants';
  cmp_ok $V->warnings, '>', 0, 'We found some warnings in this feed';
}

CRITICAL: {
  my $V;
  lives_ok { $V = _C $FEEDS{critical} } 'Critical feed should build and return';
  isa_ok $V, $VALIDATOR;
}

MIXTURE: {
  my $V;
  lives_ok { $V = _C $FEEDS{mixture} } 'Mixture feed should build and return';
  isa_ok $V, $VALIDATOR;
}


